package com.logistics.inventory.controller;

import com.logistics.inventory.entity.model.InventoryDetailPage;
import com.logistics.inventory.entity.model.InventoryPage;
import com.logistics.inventory.entity.model.UpdStation;
import com.logistics.inventory.service.InventoryDetailService;
import com.logistics.inventory.service.InventoryService;
import com.logistics.utils.bean.ResultPager;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("lgs/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    @Autowired
    private InventoryDetailService inventoryDetailService;

    @PutMapping("/modifyStationOrContainer")
    public ResponseEntity modifyStationOrContainer(@RequestBody  UpdStation updStation) throws MessageException {
        inventoryService.updateStationOrContainer(updStation);
        return ResponseUtil.success();
    }

    /**
     * 删除站点或托盘
     * @param code
     * @param isFlag
     * @return
     * @throws MessageException
     */
    @DeleteMapping("/removeStationOrContainer/{code}/{isFlag}")
    public ResponseEntity removeStationOrContainer(@PathVariable("code") String code, @PathVariable("isFlag") String isFlag) throws MessageException {
        inventoryService.deleteStationOrContainer(code, isFlag);
        return ResponseUtil.success();
    }

    /**
     *  库存查询
     * @param inventoryPage
     * @return
     * @throws MessageException
     */
    @PostMapping("/getInventoryPage")
    public ResponseEntity getInventoryPage(@RequestBody InventoryPage inventoryPage) throws MessageException {
        ResultPager resultPager =inventoryService.getInventoryPage(inventoryPage);
        return ResponseUtil.success(resultPager);
    }

    /**
     *  库存明细查询
     * @param inventoryDetailModel
     * @return
     * @throws MessageException
     */
    @PostMapping("/getContainerDetail")
    public ResponseEntity getContainerDetail(@RequestBody InventoryDetailPage inventoryDetailModel) throws MessageException {
        return ResponseUtil.success(inventoryDetailService.getContainerDetail(inventoryDetailModel));
    }

}
